package tfts

type Shield struct {
	champ  *Fight
	name   string
	health int
	end    int // 结束时间,单位tick
}

func (s *Shield) Taken(dmg int) (remain int, dec int) {
	if !s.valid() {
		return dmg, 0
	}
	if s.health >= dmg {
		s.health -= dmg
		dec = dmg
	} else {
		dec = s.health
		s.health = 0
	}
	traceLog("%4.1f秒:[%s]护盾消耗%d, 剩余护盾值%d\n", s.champ.current(), s.name, dec, s.health)
	return dmg - dec, dec
}

func (s *Shield) valid() bool {
	return s.health > 0 && s.end >= s.champ.ticks
}

func (s *Shield) handle(e Event) {
	if e != TimeGoE {
		return
	}
	if s.end < s.champ.ticks && s.health > 0 {
		s.health = 0
		traceLog("%4.1f秒:[%s]护盾过期, 剩余护盾值%d\n", s.champ.current(), s.name, s.health)
	}
}
